package com.factory;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;

//@Entity
public class Download {
	static JSONArray myJsonArray;
	private static HttpURLConnection httpConn;
	JSONObject jsonObject = new JSONObject();

	public static JSONObject Down(String src) throws Exception {
		String urc = "https://api.douban.com/v2/book/isbn/:" + src;
		URL url = new URL(urc);
		httpConn = (HttpURLConnection) url.openConnection();
		int responseCode = httpConn.getResponseCode();
		System.out.println(responseCode);
		if (responseCode != 200) {
			return null;
		}
		BufferedReader br = new BufferedReader(new InputStreamReader(
				httpConn.getInputStream(), "utf-8"));
		String destStr = "";
		String inputLin = "";
		while ((inputLin = br.readLine()) != null) {
			destStr += inputLin;
		}
		JSONObject object3 = (JSONObject) JSONSerializer.toJSON(destStr);
		return object3;
	}

}